package com.ny.dao.impl;

import com.ny.dao.ManagerDao;
import com.ny.entity.Manager;
import com.ny.until.DbUntil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ManagerDaoImpl implements ManagerDao {
    private DbUntil  dbUntil = new DbUntil();
    @Override
    public Manager login(String username, String password) throws Exception {
        Connection  connection = dbUntil.getCon();
        String sql = "select * from managers where name=? and password=?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, password);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()) {
            Manager manager = new Manager();
            manager.setManagerId(resultSet.getInt("manager_id"));
            manager.setName(resultSet.getString("name"));
            manager.setPassword(resultSet.getString("password"));
            return manager;
        }
        return null;
    }
}
